#include<iostream>
#include"contral.h"
using namespace std;


contral::contral()
{
	cout<<"contral()"<<endl<<endl;
	_map.insert(pair<type,view *>(MSG_TYPE_REGISTER,new view_register()));
	_map.insert(pair<type,view *>(MSG_TYPE_LOGIN,new view_login()));
	_map.insert(pair<type,view *>(MSG_TYPE_EXIT,new view_exit()));
	_map.insert(pair<type,view *>(MSG_TYPE_TALK_ONE,new view_talkone()));
	_map.insert(pair<type,view *>(MSG_TYPE_TALK_ONE_MSG,new view_talkonemsg()));
	_map.insert(pair<type,view *>(MSG_TYPE_OFFLINENOTE,new view_offlinenote()));
	///////////
}
contral::~contral()
{
	cout<<"~contral()"<<endl<<endl;
}

void contral::process(char *buff,int cli_fd)
{
	cout<<"contral::process"<<endl<<endl;
	//解析buff -》json
	Json::Value val;
	Json::Reader read;
	if(-1 == read.parse(buff,val))
	{
		cout<<"json prase fail;"<<endl;
		
	}
	else 
	{
		int index=val["type"].asInt();
		type key=(type)index;
		cout<<"seq type::"<<key<<endl<<endl;
		_map[key]->process(val,cli_fd);


	}
}
